home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / scbench.arc / GRAPH88.C < prev    next >
Text File  |  1980-01-01  |  6KB  |  279 lines

  1. /*
  2. ** BYTE Small-C Graphics Display Benchmark
  3. ** Version 1 for 8088/8086/80286 PC Machines
  4. ** March, 1988
  5. ** Written in BYTE Small-C
  6. ** Based on Small-C by J.E. Hendrix
  7. **
  8. ** Operation:
  9. ** 1. Prompt for which mode the user wants to test.
  10. ** 2. Save current graphics mode, flip to new mode.
  11. ** 3. Calculate center of screen based on new mode.
  12. ** 4. Turn on timer.
  13. ** 5. Draw an initial circle of radius 20.
  14. ** 6. Draw NUMCIRC circles, performing flood fill of doughnut
  15. **    area formed for each circle.
  16. ** 7. Turn off stopwatch.
  17. ** 8. Flip back to original mode.
  18. ** 9. Report results and exit.
  19. **
  20. */
  21.  
  22. #include stdio.h
  23.  
  24. #define NUMCIRC 7    /* Number of circles to draw */
  25.  
  26. int tblock[4];        /* Timer block */
  27. int vblock[3];        /* Video block */
  28. int mode;        /* Global variable for mode */
  29. int esseg;        /* ES register */
  30.  
  31. extern svmode();
  32. extern gvmode();
  33. extern setp();
  34.  
  35. main()
  36. {
  37.     int cx,cy;    /* Center of screen */
  38.     int color;    /* color */
  39.     int i,radius;
  40. int j;
  41. /*
  42. ** Save current video mode
  43. */
  44.     gvmode(vblock);
  45. /*
  46. ** Prompt for new mode
  47. */
  48.     printf("BYTE Graphics Benchmark\n");
  49.     printf("What video mode?\n");
  50.     printf("(Enter 255 for Hercules Monochrome):");
  51.     fscanf(stdin,"%d",&mode);
  52. /*
  53. ** Verify valid mode
  54. */
  55.     switch(mode) {
  56.  
  57.     case 4:
  58.     case 5:
  59.     case 6:
  60.     case 13:
  61.     case 14:
  62.     case 15:
  63.     case 16:
  64.     case 17:
  65.     case 18:
  66.     case 19:
  67.     case 255: break;
  68.     default: {
  69.       printf("Not a valid mode\n");
  70.       exit(0);
  71.     }
  72.     }
  73. /*
  74. ** Set the new video mode
  75. */
  76.     svmode(mode);
  77. /*
  78. ** Set up foreground colors and cx,cy based on mode
  79. */
  80.  
  81.     switch(mode) {
  82.       case 4:
  83.       case 5:  cx=160;
  84.            cy=100;
  85.            color=3;    /* Set to white */
  86.            esseg=-18432; /* b800h for es */
  87.            if(mode==4) setcga4(); /* Set the color palettes */
  88.            break;
  89.  
  90.       case 6:  cx=320;
  91.            cy=100;
  92.            color=1;    /* Set to white */
  93.            esseg=-18432; /* b800h for es */
  94.            setcga6(15); /* Set color palette */
  95.            break;
  96.  
  97.       case 13: cx=160;
  98.            cy=100;
  99.            color=7;    /* Set to white */
  100.            esseg=-24576; /* a000h for es */
  101.            break;
  102.  
  103.       case 14: cx=320;
  104.            cy=100;
  105.            color=15;    /* Set to white */
  106.            esseg=-24576; /* a000h for es */
  107.            break;
  108.  
  109.       case 15: cx=320;
  110.            cy=175;
  111.            color=1;
  112.            esseg=-24576; /* a000h for es */
  113.            break;
  114.  
  115.       case 16: cx=320;
  116.            cy=175;
  117.            color=7;    /* Mid-intensity white */
  118.            esseg=-24576; /* a000h for es */
  119.            break;
  120.  
  121.       case 17:
  122.       case 18: cx=320;
  123.            cy=240;
  124.            color=1;    /* Whatever */
  125.            esseg=-24576;  /* a000h for es */
  126.            break;
  127.  
  128.       case 19: cx=160;
  129.            cy=100;
  130.            color=15;    /* CGA default white */
  131.            esseg=-24576; /* a000h for es */
  132.            break;
  133.        case 255: cx=360;    /* Hercules */
  134.              cy=174;
  135.              color=1;
  136.              esseg=-20480; /* b000h for es */
  137.              break;
  138.     }
  139. /*
  140. ** Set the ES register
  141. */
  142. #asm
  143.     MOV    AX,_ESSEG
  144.     MOV    ES,AX
  145. #endasm
  146. /*
  147. ** Start the timer
  148. */
  149.     gtime(tblock);
  150. /*
  151. ** Draw a circle of radius 20
  152. */
  153.     radius=20;
  154.     circ(cx,cy,radius,color);
  155.  
  156. /*
  157. ** Alternately draw new circles of radius 30,40,50,60,70, 80 and 90,
  158. ** and flood the region in between.
  159. */
  160.     for(i=0;i<NUMCIRC;++i) {
  161.       radius+=10;
  162.       circ(cx,cy,radius,color);
  163.       flood(cx+radius-5,cy,color);
  164.     }
  165. /*
  166. ** Shut off timer
  167. */
  168.     calctim(tblock);
  169.  
  170. /*
  171. ** Flip back to original mode
  172. */
  173.     svmode(vblock[0]);
  174.  
  175. /*
  176. ** End of test -- report results
  177. */
  178.     printf("Elapsed time (HH:MM:SS:1/100ths)\n");
  179.     printf("%d:%d:%d:%d\n",tblock[0],tblock[1],tblock[2],tblock[3]);
  180.  
  181.     exit(0);
  182. }
  183.  
  184. /*
  185. ** Set cga palette for mode 4
  186. */
  187. setcga4()
  188. {
  189. #asm
  190.     MOV    AH,0BH
  191.     MOV    BX,257
  192.     INT    10H        ;Select cyan-violet-white
  193. #endasm
  194. }
  195. /*
  196. ** Set cga palette for mode 6
  197. */
  198. setcga6(color)  int color;
  199. {
  200. #asm
  201.     MOV    AH,0BH
  202.     MOV    BP,SP
  203.     MOV    BL,2[BP]
  204.     MOV    BH,0
  205.     INT    10H
  206. #endasm
  207. }
  208.  
  209. /*
  210. ** Draw a circle of color, radius r.  Centered at cx,cy.
  211. ** Note that we assume (ha!) square pixels and global variable
  212. ** mode is set.
  213. ** This routine uses an algorithm given by David Troendle
  214. ** in the May-June 1984 issue of Sextant Magazine
  215. */
  216. circ(cx,cy,r,color)
  217. int cx,cy,r,color;
  218. {
  219.     int x,y,dv;
  220. int ch;
  221. /*
  222. ** Do initial 4 corners
  223. */
  224.     setp(cx+r,cy,color,mode);
  225.     setp(cx,cy+r,color,mode);
  226.     setp(cx-r,cy,color,mode);
  227.     setp(cx,cy-r,color,mode);
  228. /*
  229. ** Do arc from 0 to 45 degrees
  230. */
  231.     x=r;
  232.     y=0;
  233.     dv=0;
  234.     do {
  235.       dv=dv+y+y+1;    /* Deviation change due to y */
  236.       y+=1;
  237.       if (dv>x) {
  238.             dv=dv-x-x+1;    /* Reduce deviation */
  239.           x-=1;
  240.           }
  241. /*
  242. ** Now do reflections
  243. */
  244.       setp(cx+x,cy+y,color,mode);
  245.       setp(cx-x,cy+y,color,mode);
  246.       setp(cx+x,cy-y,color,mode);
  247.       setp(cx-x,cy-y,color,mode);
  248.       if(x!=y) {
  249.         setp(cx+y,cy+x,color,mode);
  250.         setp(cx-y,cy+x,color,mode);
  251.         setp(cx+y,cy-x,color,mode);
  252.         setp(cx-y,cy-x,color,mode);
  253.       }
  254.     } while (y<x);
  255.    return 0;
  256. }
  257.  
  258. /*
  259. ** flood(sx,sy,color)
  260. ** Flood a region with color, starting at sx,sy.
  261. ** This is a fill until ... it fills until it encounters
  262. ** color.
  263. ** NOTE: This routine assumes that global variable mode is
  264. ** set, and the ES register is loaded with the proper value.
  265. ** Also...this version does not check for hitting the edge of
  266. ** the screen.  So your region BETTER be closed.
  267. */
  268. flood(sx,sy,color)
  269. int sx,sy,color;
  270. {
  271.     setp(sx,sy,color,mode);
  272.     if(getp(sx+1,sy,mode)!=color) flood(sx+1,sy,color);
  273.     if(getp(sx-1,sy,mode)!=color) flood(sx-1,sy,color);
  274.     if(getp(sx,sy+1,mode)!=color) flood(sx,sy+1,color);
  275.     if(getp(sx,sy-1,mode)!=color) flood(sx,sy-1,color);
  276.     return;
  277. }
  278.  
  279.